import { Request, Response } from 'express';
import { successResponse } from '../utils/response';
import config from '../config';

/**
 * @swagger
 * /health:
 *   get:
 *     summary: 健康检查
 *     tags: [System]
 *     responses:
 *       200:
 *         description: 服务正常运行
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *             example:
 *               code: 200
 *               message: 服务正常运行
 *               data:
 *                 status: healthy
 *                 timestamp: "2024-01-01T00:00:00.000Z"
 *                 uptime: 3600
 *                 environment: development
 */
export const healthCheck = (req: Request, res: Response) => {
  const healthData = {
    status: 'healthy',
    timestamp: new Date().toISOString(),
    uptime: process.uptime(),
    environment: config.nodeEnv,
    version: process.env.npm_package_version || '1.0.0'
  };
  
  return successResponse(res, healthData, '服务正常运行');
};

/**
 * @swagger
 * /:
 *   get:
 *     summary: API根路径
 *     tags: [System]
 *     responses:
 *       200:
 *         description: API信息
 *         content:
 *           application/json:
 *             schema:
 *               $ref: '#/components/schemas/ApiResponse'
 *             example:
 *               code: 200
 *               message: 欢迎使用小米有品API
 *               data:
 *                 name: 小米有品API
 *                 version: "1.0.0"
 *                 description: 小米有品电商平台后端API
 *                 environment: development
 *                 documentation: /api-docs
 */
export const apiInfo = (req: Request, res: Response) => {
  const apiData = {
    name: '小米有品API',
    version: process.env.npm_package_version || '1.0.0',
    description: '小米有品电商平台后端API',
    environment: config.nodeEnv,
    documentation: '/api-docs'
  };
  
  return successResponse(res, apiData, '欢迎使用小米有品API');
};